"use strict";
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable("Courses", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER.UNSIGNED,
      },
      CategoryId: {
        type: Sequelize.INTEGER.UNSIGNED,
        allowNull: false,
      },
      UserId: {
        type: Sequelize.INTEGER.UNSIGNED,
        allowNull: false,
      },
      name: {
        type: Sequelize.STRING,
        allowNull: false,
      },
      likeCount: {
        type: Sequelize.INTEGER.UNSIGNED,
        allowNull: false,
        defaultValue: 0,
      },
      isRecommend: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: 0,
        comment: "是否为推荐课程",
      },
      imgUrl: {
        type: Sequelize.STRING,
        comment: "课程图片",
      },
      introduce: {
        type: Sequelize.TEXT,
      },
      content: {
        type: Sequelize.TEXT,
      },
      rank: {
        type: Sequelize.INTEGER.UNSIGNED,
        defaultValue: 1,
        comment: "课程排序",
      },
      chapterCount: {
        type: Sequelize.INTEGER.UNSIGNED,
        defaultValue: 0,
        comment: "课程章节数量",
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE,
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE,
      },
    });

    await queryInterface.addIndex("Courses", {
      fields: ["CategoryId"],
    });
    await queryInterface.addIndex("Courses", {
      fields: ["UserId"],
    });
    await queryInterface.addIndex("Courses", {
      fields: ["name"],
    });
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable("Courses");
  },
};
